#!/bin/bash

app_name=GTI
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`

mkdir -p tmp

build=debug

if [ $2 ]; then
  build=$2
fi

case $1 in
  b)
    echo "${build} building..."
    ionic build ios --device --${build}
    ls -l platforms/ios/build/device/
  ;;
  s)
    target_file=tmp/${app_name}_${timestamp}.ipa
    cp platforms/ios/build/device/${app_name}.ipa ${target_file}
    scp ${target_file} dev.ftbj:/home/site/files/app/iOS/
  ;;
esac

# ionic build ios --device --release
# #ionic build ios --device --release

# ls -l platforms/ios/build/device/

# target_file=tmp/${app_name}_${timestamp}.ipa

# cp platforms/ios/build/device/${app_name}.ipa ${target_file}

# scp ${target_file} dev01.ftbj:/home/site/files/app/iOS/
# scp ${target_file} dev01.ftbj:/home/site/files/app/iOS/${app_name}_latest.ipa

# cordova build ios --device
# /usr/bin/xcrun -sdk iphoneos PackageApplication "$(pwd)/$PROJECT_NAME.app" -o "$(pwd)/$PROJECT_NAME.ipa"
# /usr/bin/xcrun -sdk iphoneos PackageApplication -v /home/user/app/build/device/MyApp.app -o /home/user/app/build/device/MyApp.ipa --sign "iPhone Development" --embed "7151ab45-6085-4ea1-9bcd-022b5cebe44b"

# Signing Identity:     "iPhone Distribution: Beijing Fractal Technology Co., Ltd. (MMER3FUMUS)"
# Provisioning Profile: "XC Ad Hoc: *"
#                       (5e845531-5a3e-4441-96bc-fbbf18fc75b9)

# {
#     "ios": {
#         "debug": {
#             "codeSignIdentity": "iPhone Development",
#             "provisioningProfile": "926c2bd6-8de9-4c2f-8407-1016d2d12954"
#         },
#         "release": {
#             "codeSignIdentity": "iPhone Distribution",
#             "provisioningProfile": "70f699ad-faf1-4adE-8fea-9d84738fb306"
#         }
#     }
# }

# {
#      "ios": {
#          "debug": {
#              "codeSignIdentitiy": "iPhone Developer",
#              "provisioningProfile": "your-dev-provisioning-profile-UUID-here"
#          },
#          "release": {
#              "codeSignIdentitiy": "iPhone Distribution",
#              "provisioningProfile": "your-distribution-provisioning-profile-UUID-here"
#
#          }
#      }
#  }
